<!DOCTYPE HTML>
<html>

<head>
        {include file="public/header" title="我的登录二维码" /}

</head>

<body>

        <header class="weui-btn weui-btn_primary">生成登录二维码</header>

        <div class="weui-form-preview">

                <div style="text-align: center;margin-top: 50px; ">
                        <img id="img" style="display: inline-block; " />
                        <div id="qrcodeCanvas" style="display: none;"></div>
                </div>
        </div>

        {include file="public/footer" /}

        <!--引入生成二维码的js库-->
        <script src="/static/js/jquery.qrcode.min.js"></script>
        <script>
                $(function () {
                        /*生成二维码的方法*/
                        var qr = jQuery('#qrcodeCanvas').qrcode({
                                render: "canvas",
                                text: '{$result.qrCodeUrl}',
                                width: "200",               //二维码的宽度
                                height: "200",              //二维码的高度
                                background: "#ffffff",       //二维码的后景色
                                foreground: "#000000"  //二维码的前景色
                        });
                        var canvas = qr.find('canvas').get(0);
                        $('img#img').attr('src', canvas.toDataURL('image/jpg'));
                //ajax轮询判断用户是否扫码登录
                setInterval(function(){
                        $.post('/index/Index/qrLogin',{'session_id':'{$session_id}'},function(res){
                        if(res.code==1){
                                $.toast(res.msg, 2000);
                                location.href='/index/Index/getMyInfo';
                        }else{
                              console.log(res.msg);
                        }
                });

                },1500);

                });



        </script>

</body>






</html>